import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { Column, Entity, PrimaryGeneratedColumn, PrimaryColumn } from 'typeorm';

@Entity({
  name: 'Person',
  synchronize: false,
})
export class Person {
  @ApiProperty({ example: 0 })
  @PrimaryGeneratedColumn()
  personId: number;
  @ApiProperty({ example: 'zhangsan' })
  @Column()
  name: string;
  @ApiProperty({ example: 10 })
  @Column()
  age: number;
  @ApiProperty({ example: true })
  @Column()
  sex: boolean;
  @ApiProperty({ example: '2022-02-02T11:11:11' })
  @Column()
  birthday: Date;
  @ApiProperty({ example: '自我介绍' })
  @Column()
  selfDescription: string;
}
export class PersonQueryConditionEx {
  //   name: string;
  @ApiProperty({ example: '' })
  @Rule(RuleType.string().allow('').allow(null).required())
  nameLike: string;
  // age: number;  minXXX maxXXX ;  startXXTime ,endXXTime;
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().allow(null).required())
  minAge: number;
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().allow(null).required())
  maxAge: number;
  @ApiProperty({ example: 1 })
  @Rule(RuleType.number().min(1).required())
  pageNum: number;
  @ApiProperty({ example: 3 })
  @Rule(RuleType.number().min(1).required())
  pageSize: number;
}

// 有什么样的 实体类 entity
// 就会有与之对应的 表结构 table
// 就会有专供该实体类配套的仓库repo repository（数据访问层）dao data access object
// 会有一堆配套dto
// 有配套的controller 甚至 service
export class PersonQueryCondition {
  @ApiProperty({ example: 2 })
  @Rule(RuleType.number().required())
  pageNum: number;
  @ApiProperty({ example: 3 })
  @Rule(RuleType.number().required())
  pageSize: number;
  //   name: string;  %%
  // 一般对于实体类的字符串字段 需要一个条件取模糊描述
  @ApiProperty({ example: 'ang' })
  @Rule(RuleType.string().allow('').allow(null).required())
  nameLike: string;
  //   age: number;
  // 一般对于实体类中日期和数字字段需要两个条件取对应描述
  @ApiProperty({ example: 18 })
  @Rule(RuleType.number().required())
  minAge: number;
  @ApiProperty({ example: 100 })
  @Rule(RuleType.number().required())
  maxAge: number;
  // 一般对于实体类中的枚举字段，需要考虑使用Array<enum>对应描述
}

@Entity({
  name: 'SomeBill',
  // true 自动建表，false取消自动建表
  synchronize: false,
})
export class SomeBill {
  @ApiProperty({ example: 'HS001' })
  @Rule(RuleType.string().required())
  @PrimaryColumn()
  someBillId: string;
  @ApiProperty({ example: 'toSubmit' })
  @Rule(RuleType.string().required())
  @Column()
  billState: string;
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().required())
  @Column()
  price: number;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column()
  createTime: Date = new Date();
}
